package com.xinsoft.controller.basic;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysNoticeSetDTO;
import com.xinsoft.entity.dto.SysNoticeSetPageParam;
import com.xinsoft.service.SysNoticeSetService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/notice/set")
public class SysNoticeSetController {

    @Autowired
    private SysNoticeSetService sysNoticeSetService;

    /**
     * 新增
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/add")
    public Response<?> add(@RequestBody SysNoticeSetDTO sysNoticeSetDTO) {
        // 参数校验
        ValidatorUtils.validateEntity(sysNoticeSetDTO);
        return Response.succeed(sysNoticeSetService.addNoticeSet(sysNoticeSetDTO));
    }

    /**
     * 更新
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/edit")
    public Response<?> edit(@RequestBody  SysNoticeSetDTO sysNoticeSetDTO) {
        // 参数校验
        ValidatorUtils.validateEntity(sysNoticeSetDTO);

        return Response.succeed(sysNoticeSetService.editNoticeSet(sysNoticeSetDTO));
    }

    /**
     * 获取消息设置
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(sysNoticeSetService.getSysNoticeSet(id));
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/del")
    public Response<?> del(@RequestBody List<Integer> ids) {
        sysNoticeSetService.del(ids);
        return Response.succeed();
    }

    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody SysNoticeSetPageParam sysNoticeSetPageParam) {
        return Response.succeed(sysNoticeSetService.findPageListByParam(sysNoticeSetPageParam));
    }

    /**
     * 获取节点动作
     */
    @GetMapping("/getNodeActionList")
    public Response<?> getNodeActionList(@RequestParam(value = "actionName", defaultValue = "", required = true) String actionName) {
        return Response.succeed(sysNoticeSetService.getNodeActionList(actionName));
    }

    /**
     * 获取自定义动作
     */
    @GetMapping("/getCustomActionList")
    public Response<?> getCustomActionList(@RequestParam(value = "actionName", defaultValue = "", required = true) String actionName) {
        return Response.succeed(sysNoticeSetService.getCustomActionList(actionName));
    }
}
